package com.xg.demo.controller;

import com.xg.demo.listener.MyEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @author hans
 * @version 1.0
 * @date 2023/04/24/15:24
 * @description 自定义监听事件实现
 */
@RestController
public class EventController {

    @Autowired
    private ApplicationContext applicationContext;

    @GetMapping("/hello")
    public String helloEvent() {
        // 发布事件
        applicationContext.publishEvent(new MyEvent(new Object()));
        return "hello";
    }
}
